
window.onload = function(){

    //返回顶部
    var tpTop = document.getElementById('tpTop');
    var time = null;
    var isTop = true;
        cancelScroll = false;

    //var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;

    window.onscroll = function(){
        //if( osTop > clientHeight ){
        //    tpTop.style.display = 'block'
        //}
        //else{
        //    tpTop.style.display = 'none';
        //}

        if( !isTop ){
            clearInterval(time);
        }
        isTop = false;
    }

    tpTop.onclick = function(){
        if( cancelScroll == false ){
            time = setInterval(function(){
                var osTop = document.documentElement.scrollTop || document.body.scrollTop;
                var isSpeed = Math.floor(-osTop/10);
                document.documentElement.scrollTop = document.body.scrollTop = osTop + isSpeed;
                isTop = true;
                if( osTop == 0 ){
                    clearInterval(time);
                    cancelScroll = true;
                }
            }, 30)
        }
        else{
            clearInterval(time);
            cancelScroll = false;
        }
    }


    //后退
    var backbutton = document.getElementById('backbutton');
        backbutton.onclick = function(){
            history.back();
        };



    //页面动态加载数据
    var page = 1;

    window.onscroll = function(){

        var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        var windowHeight = document.documentElement.offsetHeight || document.body.offsetHeight;

        var change = (windowHeight - clientHeight - scrollTop) / clientHeight;

        if( change < 0.02 ){
            page++;
            ListData(page);
        }
        
        console.log(clientHeight, scrollTop, windowHeight, change);
    }
}